import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../providers/font_size_provider.dart';

class FontSizeSettingsScreen extends StatelessWidget {
  const FontSizeSettingsScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final fontSizeProvider = Provider.of<FontSizeProvider>(context);
    final currentScale = fontSizeProvider.fontScale;
    
    return Scaffold(
      appBar: AppBar(
        title: const Text('字体大小设置'),
        centerTitle: true,
      ),
      body: Column(
        children: [
          // 预览区域
          Expanded(
            child: Center(
              child: Card(
                margin: const EdgeInsets.all(16),
                child: Padding(
                  padding: const EdgeInsets.all(16),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text(
                        '字体大小预览',
                        style: TextStyle(
                          fontSize: 20 * currentScale,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      const SizedBox(height: 16),
                      Text(
                        '这是正文字体大小预览，您可以通过下方的滑块调整应用中的字体大小。',
                        style: TextStyle(fontSize: 16 * currentScale),
                        textAlign: TextAlign.center,
                      ),
                      const SizedBox(height: 16),
                      Text(
                        '这是小号字体预览文本。',
                        style: TextStyle(fontSize: 14 * currentScale),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
          
          // 控制区域
          Container(
            padding: const EdgeInsets.all(16),
            decoration: BoxDecoration(
              color: Theme.of(context).colorScheme.surface,
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withOpacity(0.1),
                  blurRadius: 4,
                  offset: const Offset(0, -2),
                ),
              ],
            ),
            child: Column(
              children: [
                // 字体大小滑块
                Row(
                  children: [
                    const Icon(Icons.text_fields, size: 20),
                    Expanded(
                      child: Slider(
                        value: currentScale,
                        min: 0.8,
                        max: 1.4,
                        divisions: 6,
                        label: _getFontSizeLabel(currentScale),
                        onChanged: (value) {
                          fontSizeProvider.setFontScale(value);
                        },
                      ),
                    ),
                    const Icon(Icons.text_fields, size: 28),
                  ],
                ),
                
                // 按钮组
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    // 减小按钮
                    ElevatedButton.icon(
                      onPressed: currentScale > 0.8
                          ? () => fontSizeProvider.decreaseFontSize()
                          : null,
                      icon: const Icon(Icons.remove),
                      label: const Text('减小'),
                    ),
                    
                    // 重置按钮
                    OutlinedButton(
                      onPressed: currentScale != 1.0
                          ? () => fontSizeProvider.resetFontSize()
                          : null,
                      child: const Text('重置'),
                    ),
                    
                    // 增大按钮
                    ElevatedButton.icon(
                      onPressed: currentScale < 1.4
                          ? () => fontSizeProvider.increaseFontSize()
                          : null,
                      icon: const Icon(Icons.add),
                      label: const Text('增大'),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
  
  // 获取字体大小标签
  String _getFontSizeLabel(double scale) {
    if (scale <= 0.8) return '极小';
    if (scale <= 0.9) return '较小';
    if (scale <= 1.0) return '标准';
    if (scale <= 1.1) return '中等';
    if (scale <= 1.2) return '较大';
    if (scale <= 1.3) return '大';
    return '极大';
  }
}